#include "GLUTHelper.h"
#include "../EngineGLDef.h"
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL\glut.h>

#ifdef __DISABLE_GLUT_CONSOLE_WINDOWS__
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") /* for hiding console window */
#endif


IEngine *pEngineRef;


void UpdateCB()
{
	pEngineRef->Update();
}

void ResizeCB(int width, int height)
{
	((IGLRenderer *)pEngineRef->pRenderer)->OnResizeWindow(width,height);
}
void KeypressCB(unsigned char key, //The key that was pressed
					int x, int y) //The current mouse coordinates
{    
	pEngineRef->pInput->RegisterKeyPressed((KeyCodeType) key);
}

GLUTHelper::GLUTHelper(void)
{
}


GLUTHelper::~GLUTHelper(void)
{
}


void GLUTRegisterCBReference(IEngine *engine)
{
	pEngineRef = engine;

	glutDisplayFunc(UpdateCB);
	glutIdleFunc(UpdateCB);
	glutReshapeFunc(&ResizeCB);
	glutKeyboardFunc(&KeypressCB);
	/*

	glutMouseFunc(&Framework::Mouse);
	glutSpecialFunc(&Framework::Special); */
}

void GLUTCreateWindow(int argc, char **argv, char* name, int x, int y, int width, int height)
{
	glutInit(&argc, argv );
	glutInitDisplayMode(  GLUT_DOUBLE | GLUT_RGBA  | GLUT_DEPTH);
    
	glutInitWindowPosition(x,y);
    glutInitWindowSize(width,height);

    

	int i  =glutCreateWindow(name);

	
}

void GLUTUpdate()
{
	glutMainLoop();
}

void GLVersion()
{
	printf("\n OpenGL version %s \n" , glGetString(GL_VERSION));
}